package com.sw.study.springmvc.demo.controller;

import com.sw.study.springmvc.annotation.Security;
import com.sw.study.springmvc.annotation.SwAutowired;
import com.sw.study.springmvc.annotation.SwController;
import com.sw.study.springmvc.annotation.SwRequestMapping;
import com.sw.study.springmvc.demo.service.IDemoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by sw on 2020/4/9.
 */
@SwController
@SwRequestMapping("/demo")
public class DemoController {
    @SwAutowired
    private IDemoService demoService;

    /**
     *
     * @param request
     * @param response
     * @param name
     * @return
     */
    @Security(value = {"zhangsan","lisi"})
    @SwRequestMapping("/query")
    public String query(HttpServletRequest request, HttpServletResponse response,String username) throws IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write(username+",恭喜您，拥有权限-》hello world");
        return  demoService.query(username);
    }


    public void setDemoService(IDemoService demoService) {
        this.demoService = demoService;
    }
}